package com.woniuxy.huayoung.controller;

import com.woniuxy.huayoung.entity.HotelReview;
import com.woniuxy.huayoung.entity.TravelReview;
import com.woniuxy.huayoung.result.ResponseResult;
import com.woniuxy.huayoung.service.HotelReviewService;
import com.woniuxy.huayoung.service.TravelReviewService;
import com.woniuxy.huayoung.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/hotelreview")
public class HotelReviewController {
    //日志对象
    private static final Logger logger = LoggerFactory.getLogger(UserController.class);
    @Resource
    private UserService userService;
    @Resource
    private HotelReviewService hotelReviewService;

    @GetMapping("/findHotelReview")
    public ResponseResult<List<HotelReview>> findHotelReview(HttpServletRequest request){
        //得到token
        String token = request.getHeader("authorization");
        int uid = userService.findIdByToken(token);
        List<HotelReview> hotelReview = hotelReviewService.findByUid(uid);
        return new ResponseResult<List<HotelReview>>(200,"查询成功",hotelReview);
    }

    @GetMapping("/findAll")
    public ResponseResult<List<HotelReview>> findAll(){
        List<HotelReview> reviews = hotelReviewService.findAll();

        return new ResponseResult<List<HotelReview>>(200,"查询成功",reviews);
    }

    @GetMapping("/verify")
    public ResponseResult<List<HotelReview>> verify(){
        List<HotelReview> reviews = hotelReviewService.verify();

        return new ResponseResult<List<HotelReview>>(200,"查询成功",reviews);
    }

    @PostMapping("/verifypass")
    public ResponseResult<List<HotelReview>> verify(@RequestBody Map<String,Integer> map){
        Integer id = map.get("id");
        List<HotelReview> reviews = hotelReviewService.verifypass(id);
        return new ResponseResult<>(200,"审核成功",reviews);
    }

    @PostMapping("/verifynotpass")
    public ResponseResult<List<HotelReview>> verifynotpass(@RequestBody Map<String,Object> map){
        List<HotelReview> reviews = hotelReviewService.verifynotpass(map);

        return new ResponseResult<List<HotelReview>>(200,"提交成功",reviews);
    }

}
